package com.springbootdemo_8081.controller;


import com.springbootdemo_8081.pojo.User;
import com.springbootdemo_8081.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
public class UserController {
    @Autowired
    public UserService userService;
    @RequestMapping("/getAllUser")
    public List<User> getAllUser(HttpServletResponse response, HttpServletRequest request){
        response.setHeader("Access-Control-Allow-Origin","*");
        response.setCharacterEncoding("utf-8");
        List<User> users = userService.selAllUser();
        return users;
    }
    @RequestMapping("/getOne/{id}")
    public User getUser(HttpServletResponse response,  @PathVariable("id") int id){
        response.setHeader("Access-Control-Allow-Origin","*");
        response.setCharacterEncoding("utf-8");
        User user = userService.selUserById(id);
        System.out.println("跑了11111111");
        return user;
    }
}
